var cur={
		action:{
			
		},constant:{
			pageNo:1,
			pageSize:15,
		}
}

;$(function() {
	getDeptList();
	getListPage();
})
 var tale = new $.tale();
function getListPage(){
	var  dept = $("#dept_select").val();
	$.ajax({
    	url: ctxPath+"/agency/workDynamic/getPage",
        type: 'POST',
        data: {pageNo:cur.constant.pageNo,pageSize:cur.constant.pageSize,"deptId":dept},
        success: function(d){
        	 if(d.data!=null){
        		 var html="";
        	$.each(d.data.dataList,function(i,item){
        		html+=toHtml(item);
        	})	
        	$("#list_result").html(html);
        	} 
        getPage(d.data.pages,d.data.total);	 
        }
    });
}

//分页
function getPage(pageCount,totalCount){
	kkpager.total =pageCount ;//总页码
	kkpager.totalRecords = totalCount;//总条数
	kkpager.generPageHtml({
		pno : 0,
		mode : 'click',//默认值是link，可选link或者click
		click : function(n){
			cur.constant.pageNo = n;
			getListPage();
			this.selectPage(n);
		    return false;
		}
	});
}

 function toHtml(data){
	 var content ="";
	 if(data.title!=null){
		 content= data.title;
	 }
	 var date = data.updateTime;
	 if(date==null){
		 date= data.createTime;
	 }
	 return '<tr>'
         +'<td>'
         +data.deptName
         +'</td>'
         +'<td>'
         +content
         +'</td>'
         +'<td>'
         +date
         +'</td>'
         +'<td>'
         +'<a  class="btn btn-primary btn-sm waves-effect waves-light m-b-5" href="/agency/workDynamic/edit/'+data.id+'"><i class="fa fa-edit"></i>编辑</a>'
         +'<button type="button" class="btn btn-danger btn-sm waves-effect waves-light m-b-5" onclick="del(' + data.id + ')"><i class="fa fa-trash-o"></i> 删除</button>'
         +'<a  class="btn btn-info btn-sm waves-effect waves-light m-b-5" href="/agency/workDynamic/detail/'+data.id+'"><i class="fa fa-rocket"></i>详情</a>'
         +'</td>'
         +'</tr>';
 }
 
 
 
 function del(id){
    tale.alertConfirm({
        title:'确定删除吗?',
        then: function () {
            tale.post({
                url : ctxPath+'/agency/workDynamic/del',
                data: {id: id},
                success: function (result) {
                    if(result && result.success == true){
                        tale.alertOkAndReload('删除成功');
                    } else {
                        tale.alertError(result.msg || '删除失败');
                    }
                }
            });
        }
    });
 }
 
 
 /**
  * 获取组织机构
  * @returns
  */
 function getDeptList(){
 	$.ajax({
         url: ctxPath+"/agency/dept/getAllList",
         type: 'GET',
         success: function(d){
         	var success = d.success;
         	 if(success==true){
         	if(d.data!=null){
         		var result ='<option value="">请选择</option>';
         		
         	$.each(d.data,function(i,item){
         		result+='<option value="'+item.id+'">'+item.name+'</option>';	
         	})
         	$("#dept_select").html(result);
         	}	 
         	}
         	 
 	}
         })
 }
